<?php
/**
 *公告添加、修改
 */
session_start();
include "../util/DBUtil.php";
include "../util/PromptAction.php";

$login_type = $_SESSION['login_type'];//登录类型

$action = $_GET['action'];
$id = $_GET['id'];
$db = new DBUtil();
$sql = "";
$params = array($id);
if ($action=="delete"){//删除
    $sql = "delete from tb_announcement where id=?";
    $statues = $db->update($sql,$params);
    showStatue($statues);
    echo "<script>window.open('announ_info.php','info')</script>";
    return;
}elseif ($action=="edit"){//修改
    $sql = "select * from tb_announcement where id =? ";
    $result = $db->query($sql,$params)[0];
}

if ($login_type!=1){//不是管理员只可查看内容
    ?>
    <p>标题：<?php echo $result['title']?></p>
    <i>发布时间：<?php echo $result['date']?></i>
    <p>内容：<?php echo $result['content']?></p>
    <?
    return;
}
?>

<form action="../action/announ_formOK.php" method="post">
    <input type="hidden" name="id" value="<?php echo $result['id']?>">
    <table>
        <tr>
            <td>标题：</td>
            <td><input type="text" name="title" value="<?php echo $action=='edit'? $result['title']:'' ?>"></td>
        </tr>
        <tr>
            <td>内容：</td>
            <td><textarea name="content"><?php echo $action=='edit'? $result['content']:'' ?></textarea></td>
        </tr>
    </table>
    <button type="submit" >确定</button>
</form>
